package com.hushao.lims.weblims.service.impl;

import com.hushao.lims.weblims.domain.EquipmentInfo;
import com.hushao.lims.weblims.repository.EquipmentRepository;
import com.hushao.lims.weblims.service.EquipmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;

/**
 * @author 930588706
 * @date 18/1/20
 */
@Service
public class EquipmentServiceImpl implements EquipmentService {

    @Autowired
    private EquipmentRepository equipmentRepository;
    @Transactional(rollbackFor = Exception.class)
    @Override
    public EquipmentInfo save(EquipmentInfo e)throws Exception {
        return equipmentRepository.save(e);
    }

    @Override
    public EquipmentInfo findByEquipmentNameAndEquipmentSpecificationsAndEquipmentPrice(String equipmentName, String equipmentSpecifications, BigDecimal equipmentPrice) throws Exception {
        if(equipmentName.isEmpty()){
            throw new Exception("器材名称为空！");
        }
        if(equipmentSpecifications.isEmpty()){
            throw new Exception("器材规格为空！");
        }
        if(equipmentPrice==null){
            throw new Exception("器材价格为空！");
        }
        return equipmentRepository.findByEquipmentNameAndEquipmentSpecificationsAndEquipmentPrice(equipmentName,equipmentSpecifications,equipmentPrice);
    }

    @Override
    public EquipmentInfo findOne(Long equipmentId) {
        return equipmentRepository.getOne(equipmentId);
    }
}
